package com.iurac.sys;

import com.iurac.domain.DicValue;
import com.iurac.service.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Component
public class SystemInitLoader implements ServletContextAware {

    @Autowired
    DictionaryService dictionaryService;

    @Override
    public void setServletContext(ServletContext servletContext) {
        Map<String, List<DicValue>> dictionary = dictionaryService.getDictionary();
        Set<String> set = dictionary.keySet();

        for(String type: set){
            List<DicValue> dicValueList = dictionary.get(type);
            servletContext.setAttribute(type+"List",dicValueList);
        }
    }
}
